package infostroy.bookagolf.views;

import com.academysmart.bookagolf.i18n.Messages;
import infostroy.bookagolf.common.Constants.Colors;
import infostroy.bookagolf.common.Constants.Dimensions;
import infostroy.bookagolf.common.Constants.Icons;
import infostroy.bookagolf.common.enums.ElementPageCounts;
import infostroy.bookagolf.common.helpers.ImageHelper;
import infostroy.bookagolf.components.controls.GolfRoundButton;
import infostroy.bookagolf.components.dialogs.GolfAddBookingDialog;
import infostroy.bookagolf.components.inputs.GolfComboBox;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Andrew on 06.02.14.
 */
public class GolfBottomPanel extends JPanel implements Colors, Dimensions {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5894789733733698335L;

	private GolfAddBookingDialog addBookingDialog;

	private GolfComboBox comboBox;

	private JButton right;

	private JButton left;

	public GolfBottomPanel(final BookingPanel panel, boolean showButtonOrder) {
        this.setMinimumSize(Dimensions.FOOTER_DIM);
		this.setPreferredSize(Dimensions.FOOTER_DIM);
		this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
		this.setBorder(new EmptyBorder(0, 25, 0, 0));
		JLabel countLabel = new JLabel(Messages.MainWindow_outOf_text);
		comboBox = new GolfComboBox(ElementPageCounts.values());
        comboBox.setSelectedIndex(0);
		comboBox.setMaximumSize(new Dimension(20, 30));
		GolfRoundButton addButton = null;
		if (showButtonOrder) {
			addButton = new GolfRoundButton(Messages.AddOrderView_AddOrder,
					BLUE_BUTTON_BACKGROUND, BUTTON_FOREGROUND,
					BLUE_BUTTON_BORDER, BLUE_BUTTON_DIM);
			addButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
                    addBookingDialog = new GolfAddBookingDialog(Messages.AddOrderView_AddOrderDialog,
                            Colors.GREEN, Dimensions.ADD_BOOKING_DIALOG_DIM, Colors.WHITE,
                            panel);
					addBookingDialog.showDialog();
				}
			});
		}
		right = new JButton(new ImageIcon(ImageHelper.getInstance().loadImage(
				Icons.BUTTON_WITH_RIGHT_ARROW)));
		right.setContentAreaFilled(false);
		right.setBorder(new EmptyBorder(0, 0, 0, 15));
		left = new JButton(new ImageIcon(ImageHelper.getInstance().loadImage(
				Icons.BUTTON_WITH_LEFT_ARROW)));
		left.setContentAreaFilled(false);
		left.setBorder(null);

		add(countLabel);
		add(Box.createRigidArea(new Dimension(5, 5)));
		add(comboBox);
		if (showButtonOrder) {
			addButton.setAlignmentY(Component.CENTER_ALIGNMENT);
		}
		add(Box.createHorizontalGlue());
		if (showButtonOrder) {
			add(addButton);
		}
		add(Box.createHorizontalGlue());
		add(left);
		add(right);
	}

	public GolfComboBox getComboBox() {
		return comboBox;
	}

	public JButton getRightButton() {
		return right;
	}

	public JButton getLeftButton() {
		return left;
	}

}
